package com.PAT.UnSatisfying;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/12/02/10:24
 * @Description: 差11
 * @Target:
 */
public class 爱丁顿数 {

    public static void main(String[] args) {
        /*Scanner in = new Scanner(System.in);
        int len = in.nextInt();
        int[] arr = new int[len];
           for (int i = 0; i < len; i++) {
            arr[i] = in.nextInt();
        }*/
        int[] arr = new int[]{9,6,2,9,3,10,8,2,7,8};

        if (getEMethod(arr)!=Integer.MIN_VALUE){
            System.out.println(getEMethod(arr));
        }else {
            System.out.println(0);
        }
    }
    // 情况E天,满足E公里,  --- 实际上是6天,6公里,同时6存在在数组中
    // 先写出一个方法,这个方法从总天数开始,依次递减,看看满足情况不

    public static int getEMethod(int[] arr){
        int E = Integer.MIN_VALUE;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]>arr.length-i){
                continue;
            }else if (IsE(arr[i],arr)==true){
                E = arr[i];
            }
        }

        return E;
    }


    public static boolean IsE(int E,int[] arr){
        boolean flag = false;
        int count = 0;

        for (int i = 0; i < arr.length; i++) {
            if (arr[i]>E){
                count++;
            }else if (arr[i]==E){
                flag = true;
            }
        }

        if (flag=true&&E==count&&E<arr.length){
            flag = true;
        }else {
            flag = false;
        }
        return flag;
    }
}
